<template>
	<view>
		<uni-section title="">
			<view class="example">
				<!-- 基础用法，不包含校验规则 -->
				<uni-forms ref="buildingForm" :modelValue="form" label-position="left" label-width="120px"
					:rules="buildingRules">
					<uni-forms-item label="单位名称" class="form_item" required name="unitId">
						<uni-data-select v-model="form.unitId" placeholder="请选择单位名称"
							:localdata="unitList.map(item => ({value: item.id, text: item.unitName}))"></uni-data-select>
					</uni-forms-item>
					<uni-forms-item label="建筑物名称" class="form_item" required name="bdName">
						<uni-easyinput v-model="form.bdName" placeholder="请输入建筑物名称" />
					</uni-forms-item>
					<uni-forms-item label="建筑地址信息" class="form_item" required name="bdAddress">
						<uni-easyinput v-model="form.bdAddress" placeholder="请输入建筑地址信息" />
					</uni-forms-item>
					<uni-forms-item label="建筑物类别" class="form_item" required name="bdTypeId">
						<view class="uni-px-5 uni-pb-5">
							<uni-data-select v-model="form.bdTypeId" placeholder="请选择建筑物类别"
								:localdata="buildingTypeList.map(item => ({value: item.id, text: item.buildingTypeName}))"></uni-data-select>
						</view>
					</uni-forms-item>
					<uni-forms-item label="使用性质" class="form_item" required name="bdUseWayId">
						<uni-data-select v-model="form.bdUseWayId" placeholder="请选择使用性质"
							:localdata="buildingUseWayList.map(item => ({value: item.id, text: item.buildingUseWayName}))"></uni-data-select>
					</uni-forms-item>
					<uni-forms-item label="结构类型" class="form_item" required name="bdStructureId">
						<uni-data-select v-model="form.bdStructureId" placeholder="请选择结构类型"
							:localdata="buildingStructureList.map(item => ({value: item.id, text: item.buildingStructureName}))"></uni-data-select>
					</uni-forms-item>
					<uni-forms-item label="耐火等级" class="form_item" required name="bdFireResistantId">
						<uni-data-select v-model="form.bdFireResistantId" placeholder="请选择耐火等级"
							:localdata="buildingResistantList.map(item => ({value: item.id, text: item.fireResistantName}))"></uni-data-select>
					</uni-forms-item>
					<uni-forms-item label="火灾危险性" class="form_item" required name="bdFireHazardId">
						<uni-data-select v-model="form.bdFireHazardId" placeholder="请选择经济类型"
							:localdata="buildingFireHazardList.map(item => ({value: item.id, text: item.fireHazardName}))"></uni-data-select>
					</uni-forms-item>
					<uni-forms-item label="使用层数" class="form_item" required name="bdUseFloor">
						<uni-easyinput v-model="form.bdUseFloor" placeholder="请输入使用层数" />
					</uni-forms-item>
					<uni-forms-item label="建筑高度" class="form_item" name="bdHeight">
						<uni-easyinput v-model="form.bdHeight" placeholder="请输入建筑高度" />
					</uni-forms-item>
					<uni-forms-item label="建筑面积" class="form_item" name="bdSpace">
						<uni-easyinput v-model="form.bdSpace" placeholder="请输入建筑面积" />
					</uni-forms-item>
					<uni-forms-item label="建筑安全距离" class="form_item" name="bdSafeDistance">
						<uni-easyinput v-model="form.bdSafeDistance" placeholder="请输入建筑安全距离" />
					</uni-forms-item>
					<uni-forms-item label="占地面积" class="form_item" name="bdOccupySpace">
						<uni-easyinput v-model="form.bdOccupySpace" placeholder="请输入占地面积" />
					</uni-forms-item>
					<uni-forms-item label="标准层面积" class="form_item" name="bdStdFloorSpace">
						<uni-easyinput v-model="form.bdStdFloorSpace" placeholder="请输入标准层面积" />
					</uni-forms-item>
					<uni-forms-item label="地上层数" class="form_item" name="bdOverGroundFloor">
						<uni-easyinput v-model="form.bdOverGroundFloor" placeholder="请输入地上层数" />
					</uni-forms-item>
					<uni-forms-item label="地上层面积" class="form_item" name="bdOverGroundSpace">
						<uni-easyinput v-model="form.bdOverGroundSpace" placeholder="请输入地上层面积" />
					</uni-forms-item>
					<uni-forms-item label="地下层数" class="form_item" name="bdUnderGroundFloor">
						<uni-easyinput v-model="form.bdUnderGroundFloor" placeholder="请输入地下层数" />
					</uni-forms-item>
					<uni-forms-item label="地下层面积" class="form_item" name="bdUnderGroundSpace">
						<uni-easyinput v-model="form.bdUnderGroundSpace" placeholder="请输入地下层面积" />
					</uni-forms-item>
					<uni-forms-item label="隧道高度" class="form_item" name="bdTunnelHeight">
						<uni-easyinput v-model="form.bdTunnelHeight" placeholder="请输入隧道高度" />
					</uni-forms-item>
					<uni-forms-item label="隧道长度" class="form_item" name="bdTunnelLength">
						<uni-easyinput v-model="form.bdTunnelLength" placeholder="请输入隧道长度" />
					</uni-forms-item>
					<uni-forms-item label="建造日期" class="form_item">
						<uni-datetime-picker type="datetime" return-type="timestamp" v-model="form.bdFinishDate" />
					</uni-forms-item>
					<uni-forms-item label="避难层数量" class="form_item" name="bdRefugeNum">
						<uni-easyinput v-model="form.bdRefugeNum" placeholder="请输入避难层数量" />
					</uni-forms-item>
					<uni-forms-item label="避难层总面积" class="form_item" name="bdRefugeSpace">
						<uni-easyinput v-model="form.bdRefugeSpace" placeholder="请输入避难层总面积" />
					</uni-forms-item>
					<uni-forms-item label="避难层位置描述" class="form_item" name="bdRefugePosition">
						<uni-easyinput v-model="form.bdRefugePosition" placeholder="请输入避难层位置描述" />
					</uni-forms-item>
					<uni-forms-item label="消防电梯使用" class="form_item" name="bdFireElevatorUse">
						<uni-data-checkbox v-model="form.bdFireElevatorUse" :localdata="bdFireElevatorUseList" />
					</uni-forms-item>
					<uni-forms-item label="消防电梯数量" class="form_item" name="bdFireElevatorNum">
						<uni-easyinput v-model="form.bdFireElevatorNum" placeholder="请输入消防电梯数量" />
					</uni-forms-item>
					<uni-forms-item label="消防总重量" class="form_item" name="bdFireElevatorCapacity">
						<uni-easyinput v-model="form.bdFireElevatorCapacity" placeholder="请输入消防电梯容纳总重量" />
					</uni-forms-item>
					<uni-forms-item label="日常人数" class="form_item" name="bdNormalPopulation">
						<uni-easyinput v-model="form.bdNormalPopulation" placeholder="请输入日常工作时间人数" />
					</uni-forms-item>
					<uni-forms-item label="最大容纳人数" class="form_item" name="bdMaxPopulation">
						<uni-easyinput v-model="form.bdMaxPopulation" placeholder="请输入最大容纳人数" />
					</uni-forms-item>
					<uni-forms-item label="经度" class="form_item" name="gpsLng">
						<uni-easyinput v-model="form.gpsLng" placeholder="请输入经度" />
					</uni-forms-item>
					<uni-forms-item label="纬度" class="form_item" name="gpsLat">
						<uni-easyinput v-model="form.gpsLat" placeholder="请输入纬度" />
					</uni-forms-item>
					<uni-forms-item label="备注" class="form_item" name="remark">
						<uni-easyinput v-model="form.remark" placeholder="请输入备注" />
					</uni-forms-item>
				</uni-forms>
				<button type="primary" @click="submit('buildingForm')">提交</button>
			</view>
		</uni-section>
	</view>
</template>

<script>
	import {
		getDicts
	} from "@/api/system/dict/data.js"
	import {
		listUnit,
	} from "@/api/system/unit"
	import {
		listBuilding,
		getBuilding,
		delBuilding,
		addBuilding,
		updateBuilding,
		buildingType,
		buildingUseWay,
		buildingStructure,
		buildingResistant,
		buildingFireHazard,
		buildingPush
	} from "@/api/system/building"
	import config from '@/config'
	import {
		getToken
	} from '@/utils/auth'

	export default {
		data() {
			return {
				unitList: [], //单位list
				buildingTypeList: [], // 建筑物类型
				buildingUseWayList: [], //   筑物使用性质
				buildingFireHazardList: [], //   筑物火灾危险性
				buildingResistantList: [], //   建筑物耐火等级
				buildingStructureList: [], //   建筑物结构类型
				bdFireElevatorUseList: [{
					text: '是',
					value: 0
				}, {
					text: '否',
					value: 1
				}],
				form: {},
				buildingRules: {
					unitId: {
						rules: [{
							required: true,
							errorMessage: '单位不能为空'
						}]
					},
					bdName: {
						rules: [{
							required: true,
							errorMessage: '建筑物名称不能为空'
						}]
					},
					bdAddress: {
						rules: [{
							required: true,
							errorMessage: '建筑地址信息不能为空'
						}]
					},
					bdTypeId: {
						rules: [{
							required: true,
							errorMessage: '建筑物类别不能为空'
						}]
					},
					bdUseWayId: {
						rules: [{
							required: true,
							errorMessage: '使用性质不能为空'
						}]
					},
					bdStructureId: {
						rules: [{
							required: true,
							errorMessage: '结构类型不能为空'
						}]
					},
					bdUseFloor: {
						rules: [{
							required: true,
							errorMessage: '建筑使用层数不能为空'
						}]
					},

				},
			}
		},
		created() {
			this.dictList()
			this.getUnit()
		},
		methods: {
			/** 查询单位 */
			getUnit(row) {
				listUnit({
					pageNum: 1,
					pageSize: 999999,
				}).then(response => {
					this.unitList = response.rows

				})
			},
			dictList() {
				this.getBuildingType()
				this.getBuildingUseWay()
				this.getBuildingFireHazard()
				this.getBuildingResistant()
				this.getBuildingStructure()
			},
			/** 建筑物类型 */
			getBuildingType() {
				buildingType().then(response => {
					this.buildingTypeList = response.data
				})
			},
			/** 筑物使用性质 */
			getBuildingUseWay() {
				buildingUseWay().then(response => {
					this.buildingUseWayList = response.data
				})
			},
			/** 筑物火灾危险性 */
			getBuildingFireHazard() {
				buildingFireHazard().then(response => {
					this.buildingFireHazardList = response.data
				})
			},
			/** 建筑物耐火等级 */
			getBuildingResistant() {
				buildingResistant().then(response => {
					this.buildingResistantList = response.data
				})
			},
			/** 建筑物结构类型 */
			getBuildingStructure() {
				buildingStructure().then(response => {
					this.buildingStructureList = response.data
				})
			},

			submit(ref) {
				this.$refs['buildingForm'].validate().then(res => {
					addBuilding(this.form).then(response => {
						this.$modal.msgSuccess("新增成功！");
						this.form = {}
						uni.reLaunch({
							url: '/pages/system/building/index'
						});
					})
				}).catch(err => {
					console.log('err', err);
				})
			},

		}
	}
</script>

<style>
	.example {
		padding: 15px;
		background-color: #fff;
	}

	.form_item {
		margin-bottom: 15px;
	}
</style>